package tests;

import static org.junit.Assert.*;

import io.IoHandler;

import java.util.Vector;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import components.Goal;
import components.Operator;
import components.Variable;

public class IoHandlerTest {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testParseFile() {
		Vector<Variable> vars= new Vector<Variable>();
		Vector<Goal> goals= new Vector<Goal>();
		Vector<Operator> operators= new Vector<Operator>();
		
		try {
			IoHandler.ParseFile("input", vars, goals, operators);
		} catch (NumberFormatException e) {
			e.printStackTrace();
			fail("exception heppened");
		} catch (Exception e) {
			e.printStackTrace();
			fail("exception heppened");
		}
		assertTrue("number of vars correct",vars.size()==30);
		assertTrue("number of goals correct",goals.size()==6);
		assertTrue("number of operators correct",operators.size()==259);
		assertTrue("example variable",vars.elementAt(0).getDomain()==7);
		assertTrue("example variable2",vars.elementAt(0).getState()==1);
		assertFalse("example goal",goals.elementAt(0).correct());
		assertTrue("exmple oprtators",operators.elementAt(0).confirm());
	}
	
	@Test
	public void testOutputFile() {
		Vector<Variable> vars= new Vector<Variable>();
		Vector<Goal> goals= new Vector<Goal>();
		Vector<Operator> operators= new Vector<Operator>();
		
		try {
			IoHandler.ParseFile("input", vars, goals, operators);
		} catch (NumberFormatException e) {
			e.printStackTrace();
			fail("exception heppened");
		} catch (Exception e) {
			e.printStackTrace();
			fail("exception heppened");
		}
		try {
			IoHandler.outputToFile("kaki","input", vars, goals, operators);
		} catch (NumberFormatException e) {
			e.printStackTrace();
			fail("exception heppened");
		} catch (Exception e) {
			e.printStackTrace();
			fail("exception heppened");
		}
		
		assertTrue(true);
	}
	
	

}
